<link rel="stylesheet" href="../layui/css/layui.css" media="all">
<script src="../layui/layui.all.js"></script>
<style>
	.layui-form-label {width:110px}
	.layui-input-block {
		margin-left: 140px;
		width:70%;
	}
	.layui-form-text{padding-right: 44px;}
	.layui-form-switch{height: 28px;line-height: 28px;min-width: 45px;}
	.layui-form-switch i{top:6px}
	.mytitle{font-size: 20px;color: #333;border-left: 4px solid #1E9FFF;padding-left:20px;margin: 20px 0 12px;}
</style>
<h3 class="mytitle"></h3>
<div class="layui-fluid">
	<div style="padding:16px">
		<form class="layui-form" action="" lay-filter="example">
			<div class="layui-form-item" style="display: none">
				<div class="layui-block">
					<label class="layui-form-label">车道主键：</label>
					<div class="layui-input-block">
						<input type="text" name="id" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-block">
					<label class="layui-form-label">车道编号<span class="bt">*</span>：</label>
					<div class="layui-input-block">
						<input type="text" name="laneNum" lay-verify="required" autocomplete="off" placeholder="请输入车道编号" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-block">
					<label class="layui-form-label">停车区域<span class="bt">*</span>：</label>
					<div class="layui-input-block">
						<select name="areaId" id="area" lay-verify="required" lay-filter="sex">
						</select>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-block">
					<label class="layui-form-label">车道名称<span class="bt">*</span>：</label>
					<div class="layui-input-block">
						<input type="text" name="laneName" lay-verify="required" autocomplete="off" placeholder="请输入信号灯名称" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-block">
					<label class="layui-form-label">车道总车位<span class="bt">*</span>：</label>
					<div class="layui-input-block">
						<input type="text" name="totalSpace" lay-verify="required" autocomplete="off" placeholder="请输入信号灯名称" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-block">
					<label class="layui-form-label">车道剩余车位<span class="bt">*</span>：</label>
					<div class="layui-input-block">
						<input type="text" name="remainSpace" lay-verify="required" autocomplete="off" placeholder="请输入信号灯名称" class="layui-input">
					</div>
				</div>
			</div>
			<div class="bottomBtns">
				<button class="layui-btn layui-btn-primary">取消</button>
				<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">确定</button>
			</div>
		</form>
	</div>
</div>

<script>
	var $ = layui.$,
		laydate = layui.laydate,
		form = layui.form,
		index = parent.layer.getFrameIndex(window.name),
		title = {
			"add": "新增",
			"edit": "编辑"
		};

	$(".mytitle").text(title[getUrl("type")] + "车道信息配置");

	laydate.render({
		elem: '#dateT'
	});

	//获取区域
	$.ajax({
		type:'post',
		url:'../lane/getAreaList',
		async: false,
		success: function (data) {
			if (data!=null){
				console.dir(data);
				$('#area').empty();
				var html = '<option value="">请选择</option>';
				for(var i=0; i<data.length; i++){
					html += '<option value="'+data[i].id+'" >'+data[i].areaName+'</option>';
				}
				$('#area').append(html);
				form.render();
			}
		}
	});

	//获取待编辑的数据
	if (getUrl("type") == 'edit') {
		$.ajax({
			url: '../lane/getLane',
			data: {id: getUrl("id")},
			type:'post',
			success: function(data) {
				if (data!=null){
					form.val('example', data);
				}
			}
		})
	}

	form.render();

	//将新增或编辑的内容提交
	form.on('submit(demo1)', function(data) {
		$.ajax({
			url: '../lane/addOrUpdateLane',
			type: 'post',
			data: data.field,
			success: function(res) {
				parent.layer.close(index);
			}
		});
		return false;
	});
	$("form").on("click", ".layui-btn-primary", function() {
		parent.layer.close(index);
	});


	function getUrl(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]);
		return null;
	}
</script>
